<template>
  <l-layout class="l-tab-page">
    <div id="designer"></div>
    <div id="viewer"></div>
  </l-layout>
</template>

<script>
//var Report;
const api = window.$api.report.reportinfo;
export default {
  components: {},
  data() {
    return {};
  },
  mounted() {
    window.Stimulsoft.Base.StiLicense.loadFromFile("/cdn/stimulsoft/license.key");
    window.Stimulsoft.Base.Localization.StiLocalization.setLocalizationFile("/cdn/stimulsoft/zh-CHS.xml");

    //编辑调用
    var options = new window.Stimulsoft.Designer.StiDesignerOptions();
    //console.log(options);
    options.appearance.fullScreenMode = false;
    var designer = new window.Stimulsoft.Designer.StiDesigner(options, "StiDesigner", false);

    var report = new window.Stimulsoft.Report.StiReport();
    report.loadFile("/cdn/stimulsoft/SimpleList.mrt");

    var dataSet = new window.Stimulsoft.System.Data.DataSet("JSON");
    dataSet.readJsonFile("/cdn/stimulsoft/Demo.json");
    //dataSet.readXmlFile("/cdn/stimulsoft/zh-CHS.xml");
    report.regData("JSON", "JSON", dataSet);

    designer.report = report;
    designer.renderHtml("designer");
    //Report = report;

    var _this = this;
    designer.onSaveReport = function (e) {
      var jsonStr = e.report.saveToJsonString();
      //console.log(jsonStr);
      api
        .uploadreportfile({ file: _this.encode(jsonStr), reportid: "7d9be2080e2a4ceaa88aaeb189168486" })
        .then((res) => {
          _this.$message({
            type: "success",
            message: res.data.info,
          });
        });
    };

    // var dataSet = new window.Stimulsoft.System.Data.DataSet("JSON");
    // dataSet.readJson("JSON", "JSON",this.dataJson);

    //var json = report.saveDocumentToJsonString();
    //console.log(json);

    //预览调用
    /*
	 var options = new window.Stimulsoft.Viewer.StiViewerOptions(); 
	  console.log(options);
	 var viewer = new window.Stimulsoft.Viewer.StiViewer(options, 'StiViewer', false);
	 var report = new window.Stimulsoft.Report.StiReport();
	 report.loadFile('/cdn/stimulsoft/SimpleList.mrt');
	
	 var dataSet = new window.Stimulsoft.System.Data.DataSet("JSON");
	  dataSet.readJsonFile("/cdn/stimulsoft/Demo.json");
	  report.dictionary.databases.clear();
	  report.regData("JSON", "JSON", dataSet);

	 viewer.report = report;
	 viewer.renderHtml('viewer');
	 */
  },
  computed: {},
  methods: {
    encode(str) {
      // 对字符串进行编码
      var encode = encodeURIComponent(str);
      // 对编码的字符串转化base64
      var base64 = btoa(encode);
      return base64;
    },
  },
};
</script>
